import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        
        toolBar=QToolBar()
        toolBar.addWidget(QLabel('DockOption:'))

        cb=QComboBox()
        cb.addItems(QMainWindow.DockOption.__members__.keys())
        cb.currentTextChanged.connect(self.OnDockOptionChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('DockWidgetFeature:'))
        cb=QComboBox()
        cb.addItems(QDockWidget.DockWidgetFeature.__members__.keys())
        cb.currentTextChanged.connect(self.OnDockWidgetFeatureChanged)
        toolBar.addWidget(cb)

        self.addToolBar(toolBar)
        #删除main的中央布局
        center= self.centralWidget()
        del center

        self.setDockNestingEnabled(True)#允许嵌套dock
        
        self.dock1=QDockWidget(windowTitle='dock1')        
        self.dock2=QDockWidget(windowTitle='dock2')
        self.dock3=QDockWidget(windowTitle='dock3')
        self.dock4=QDockWidget(windowTitle='dock4')
        self.dock5=QDockWidget(windowTitle='dock5')
        self.dock6=QDockWidget(windowTitle='dock6')
        self.dock7=QDockWidget(windowTitle='dock7')
        self.addDockWidget(Qt.DockWidgetArea.TopDockWidgetArea,self.dock1)
        self.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea,self.dock2)
        self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea,self.dock3)
        self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea,self.dock4)
        self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea,self.dock5)
        self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea,self.dock6)
        self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea,self.dock7)
    def OnDockOptionChanged(self,text):
        option=QMainWindow.DockOption[text]
        self.setDockOptions(option)
        self.parent.OnShowMessage(f'Set DockOptions: {option}') 
    def OnDockWidgetFeatureChanged(self,text):
        feature=QDockWidget.DockWidgetFeature[text]
        self.dock1.setFeatures(feature)
        self.parent.OnShowMessage(f'Set DockWidget Feature: {feature}') 
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet